{#
 Licensed to the Apache Software Foundation (ASF) under one
 or more contributor license agreements.  See the NOTICE file
 distributed with this work for additional information
 regarding copyright ownership.  The ASF licenses this file
 to you under the Apache License, Version 2.0 (the
 "License"); you may not use this file except in compliance
 with the License.  You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing,
 software distributed under the License is distributed on an
 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
#}

{% extends "airflow/dag.html" %}

{% block head_css %}
{{ super() }}
<link href="{{ admin_static.url(filename='vendor/bootstrap-daterangepicker/daterangepicker-bs2.css') }}" rel="stylesheet"/>
<link type="text/css" href="{{ url_for('static', filename='gantt.css') }}" rel="stylesheet" />
<link type="text/css" href="{{ url_for('static', filename='tree.css') }}" rel="stylesheet" />
<style type="text/css">
  {% for state, state_color in state_color_mapping.items() %}
    rect.{{state}} {
      fill: {{state_color}};
    }
  {% endfor %}
</style>
{% endblock %}

{% block body %}
{{ super() }}
<form method="get">
  <div class="form-inline">
    Base date: {{ form.base_date(class_="form-control") }}
    Number of runs: {{ form.num_runs(class_="form-control") }}
    Run:<input type="hidden" value="{{ dag.dag_id }}" name="dag_id">
    {{ form.execution_date(class_="form-control") }}
    <input type="submit" value="Go" class="btn btn-default" action="" method="get">
    <input type="hidden" name="root" value="{{ root if root else '' }}">
    <input name="_csrf_token" type="hidden" value="{{ csrf_token() }}">
  </div>
</form>
<div style="clear: both;"></div>
<div class="container">
  <div class="gantt"></div>
</div>
{% endblock %}

{% block tail %}
{{ super() }}
<script src="{{ admin_static.url(
  filename='vendor/bootstrap-daterangepicker/daterangepicker.js') }}"></script>
<script src="{{ url_for('static', filename='d3.v3.min.js') }}"></script>
<script src="{{ url_for('static', filename='d3.tip.v0.6.3.js') }}"></script>/
<script src="{{ url_for('static', filename='gantt-chart-d3v2.js') }}"></script>
<script>
  $( document ).ready(function() {
    var dag_id = '{{ dag.dag_id }}';
    var task_id = '';
    var execution_date = '';
    data = {{ data |tojson }};
    var gantt = d3.gantt()
      .taskTypes(data.taskNames)
      .taskStatus(data.taskStatus)
      .height(data.height)
      .selector('.gantt')
      .tickFormat("%H:%M:%S");
    gantt(data.tasks);
  });
</script>

{% endblock %}
